﻿using System;
using System.Globalization;


namespace TheCollectiveNetwork.Classes.GlobalFunctions
{
            
    public class strfunc{

        /// <summary>
        /// Tests whether a string is contained within a Uri - case insensitive.
        /// </summary>
        public static bool CaseInsensitiveContains(Uri uri, string value)
        {
            string fullString = uri.ToString().ToLower(CultureInfo.InvariantCulture);
            value = value.ToLower(CultureInfo.InvariantCulture);
            return fullString.Contains(value);
        }

        /// <summary>
        /// Returns specified number of characters of a string starting from the left.
        /// </summary>
        public static string Left(string text, int length)
        {
            string rtnstring;

            if (length <= 0 || text.Length == 0)
            {
                rtnstring = string.Empty;
            }
            else if (text.Length <= length)
            {
                rtnstring = text;
            }
            else
            {
                rtnstring = text.Substring(0, length);
            }

            return rtnstring;
        }

    
    }

    // This class displays the processing indicator
    // when the system is busy
    public static class ProcessingIndicator
    {

        /* Variable Definitions */
        static int c_ApplicationBusy = 0;
        static TheCollectiveNetwork.Views.Busy c_BusyIndicatorView;

        public static void DisplayApplicationBusy()
        {
            c_ApplicationBusy += 1;

            if (c_ApplicationBusy == 1)
            {
                c_BusyIndicatorView = new TheCollectiveNetwork.Views.Busy();
                c_BusyIndicatorView.Show();
            }


        }

        public static void HideApplicationBusy()
        {
            c_ApplicationBusy -= 1;

            if (c_ApplicationBusy == 0 && c_BusyIndicatorView != null)
            {
                c_BusyIndicatorView.Close();
                c_BusyIndicatorView = null;

                // Ensure parent window is enabled
                System.Windows.Application.Current.RootVisual.SetValue(System.Windows.Controls.Control.IsEnabledProperty, true);
            }

        }

    }


   
}
